package com.ruoyi.web.controller.activityStats;

import com.ruoyi.activity_stats.domain.ActivityStats;
import com.ruoyi.activity_stats.service.IActivityStatsService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 活动效果统计Controller
 * 
 * @author 张富饶
 * @date 2025-05-22
 */
@RestController
@RequestMapping("/activity_stats/activity_stats")
public class ActivityStatsController extends BaseController
{
    @Autowired
    private IActivityStatsService activityStatsService;

    /**
     * 查询活动效果统计列表
     */
    @PreAuthorize("@ss.hasPermi('activity_stats:activity_stats:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActivityStats activityStats)
    {
        startPage();
        List<ActivityStats> list = activityStatsService.selectActivityStatsList(activityStats);
        return getDataTable(list);
    }

    /**
     * 导出活动效果统计列表
     */
    @PreAuthorize("@ss.hasPermi('activity_stats:activity_stats:export')")
    @Log(title = "活动效果统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivityStats activityStats)
    {
        List<ActivityStats> list = activityStatsService.selectActivityStatsList(activityStats);
        ExcelUtil<ActivityStats> util = new ExcelUtil<ActivityStats>(ActivityStats.class);
        util.exportExcel(response, list, "活动效果统计数据");
    }

    /**
     * 获取活动效果统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('activity_stats:activity_stats:query')")
    @GetMapping(value = "/{activityId}")
    public AjaxResult getInfo(@PathVariable("activityId") Long activityId)
    {
        return success(activityStatsService.selectActivityStatsByActivityId(activityId));
    }

    /**
     * 新增活动效果统计
     */
    @PreAuthorize("@ss.hasPermi('activity_stats:activity_stats:add')")
    @Log(title = "活动效果统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivityStats activityStats)
    {
        return toAjax(activityStatsService.insertActivityStats(activityStats));
    }

    /**
     * 修改活动效果统计
     */
    @PreAuthorize("@ss.hasPermi('activity_stats:activity_stats:edit')")
    @Log(title = "活动效果统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityStats activityStats)
    {
        return toAjax(activityStatsService.updateActivityStats(activityStats));
    }

    /**
     * 删除活动效果统计
     */
    @PreAuthorize("@ss.hasPermi('activity_stats:activity_stats:remove')")
    @Log(title = "活动效果统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable Long[] activityIds)
    {
        return toAjax(activityStatsService.deleteActivityStatsByActivityIds(activityIds));
    }
}
